# Contributor: Assaf Gordon <assafgordon@gmail.com>
# Maintainer: Assaf Gordon <assafgordon@gmail.com>
pkgname=datamash
pkgver=1.7
pkgrel=0
pkgdesc="command-line text/math procesing"
url="https://www.gnu.org/software/datamash/"
arch="all"
license="GPL-3.0-or-later"
source="https://ftpmirror.gnu.org/datamash/datamash-$pkgver.tar.gz"
subpackages="$pkgname-doc $pkgname-bash-completion:bashcomp:noarch"

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--disable-nls \
		--disable-werror \
		--with-bash-completion-dir=local
	make
}

check() {
	make check
}

package() {
	make -j1 DESTDIR="$pkgdir" install
	rm -rf "$pkgdir"/usr/share/datamash/examples \
		"$pkgdir"/usr/lib/charset.alias
}

bashcomp() {
	depends=""
	pkgdesc="Bash completions for $pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel bash-completion"

	mkdir -p "$subpkgdir"/usr/share/bash-completion/completions/
	mv "$pkgdir"/usr/share/datamash/bash-completion.d/datamash \
		"$subpkgdir"/usr/share/bash-completion/completions/
	rm -r "$pkgdir"/usr/share/datamash/bash-completion.d || true
}

sha512sums="29d82d6a1ac25a6ceb901c14fdeacbcb575771f405d844a66df525f820f1515d84989480807e466ddaa0a1ebc5cf698191538391b0c64bddf0d80462f66a5992  datamash-1.7.tar.gz"
